The invention relates to communication and network technology field, and in particular, to a method, a terminal and a network server for maintaining a connection between a terminal and a network server.
Portable devices (i.e., terminals such as cell phones, portable computers) access to the Internet through a wireless network (such as 3G). Because the number the addresses is not enough, in order to save public IP addresses, the IP address used by a portable device is usually a private address. Therefore, it is necessary to perform Network Address Transform (NAT) through a network agent means or gateway and then connect the portable device to the Internet. This may cause a host or a server on the Internet to be unable to actively initiate a connection to the handheld device.
In order to obtain some application data from a server (for example, the server push some real-time information that user cares about), one of the solutions provided in the prior art is that a portable device actively initiates a TCP or UDP connection to the server, so as to establish a connection channel between the server and the portable device, so that the server can use this TCP or UDP channel to perform data transmission. However, if there is no data transmission on the TCP or UDP connection within a period of time T, then a network agent means or a gateway corresponding to the portable device will clean up the connection state, which causes the connection to be broken. At this point, the server or the portable device cannot keep on using the connection channel continuously. The data transmission intermittent period T varies depending on different used networks. For example, in tests, a data transmission intermittent period T of some 3G networks is about 11 minutes, while a data transmission intermittent period T of some GSM networks is about 18 minutes, and so on.
In order to maintain the connection between the server and the portable device, the current solution is that the portable device transmits “heartbeat” data to the server within a period less than T (or the server transmits the “heartbeat” data to the portable device), so that the corresponding TCP or UDP channel maintains “active” state, thereby the intermediate NAT gateway will not clean up the channel. Since the data transmission intermittent periods T for different networks are different, it is difficult to determine a reasonable period for transmitting the connection-maintaining data when designing; if the period is set to be too short, it will frequently wake the CPU and the whole operating system of the portable device, which causes the portable device to consume a lot of power. Even if the “heartbeat” data is transmitted from the server to the portable device, the main CPU and the whole operating system of the portable device will be wakened to accept the data, so the handhold device consumes a lot of power as well, which shortens the portable device's continuous using time.
If the period is too long, and the connection channel cannot be maintained to be available, then some real-time data cannot be pushed from the server to the portable device in time. For the portable device which is supplied by a battery, it possibly leads to the bottleneck of the power supply when the mobile portable device uses data pushing services by the server.